home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_srgp.lha / srgp / src / srgp_echo_MAC.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-09  |  8.1 KB  |  362 lines

  1. #include "HEADERS.h"
  2. #include "srgplocal.h"
  3.  
  4. /** INFORMATION ABOUT THE LOW-LEVEL ECHOING DRIVERS
  5.  
  6. SRGP__initEchoModule ()
  7.    Must be called once, during initialization.
  8.    The echo-attribute globals must have already been given
  9.       default initial values!
  10.  
  11. SRGP__updateLocatorRubberAnchor ()
  12.    Acesses current locator rubber anchor from globals.
  13.    May be called whether rubber echo is active or not.
  14.  
  15. SRGP__enableLocatorRubberEcho ()
  16.    Accesses current locator measure info from global variables.
  17.    May be called carelessly:
  18.       1) Will not re-enable if already enabled
  19.       2) Will refuse to enable echo for a device that is:
  20.       A) not active currently, and 
  21.       B) not in a state for which echo is desired
  22.  
  23. SRGP__updateLocatorRubberEcho ()
  24.    Accesses current locator measure info from global variables.
  25.    May be called carelessly:
  26.       Will not update if device is currently disabled.
  27.  
  28. SRGP__disableLocatorRubberEcho ()
  29.    May be called carelessly:
  30.       Will not re-disable if already disabled
  31.  
  32.  
  33. SRGP__updateLocatorCursorShape ()
  34.    May be called whether or not the cursor echo is active.
  35.  
  36. SRGP__enableLocatorCursorEcho ()
  37. SRGP__disableLocatorCursorEcho ()
  38.       May be called carelessly.
  39.  
  40. SRGP__updateRawCursorPosition ()
  41.       Accesses cur_locator_measure from global variables.
  42.       Informs the underlying graphics package of the desired "cursor warp".
  43.       Automatically updates any type of locator echo: cursor or rubber.
  44.  
  45.  
  46. SRGP__updateKeyboardEchoAttributes ()
  47.    May be called whether or not key echo is active.
  48.    Obtains attributes from global variables.
  49.  
  50. SRGP__enableKeyboardEcho ()
  51. SRGP__updateKeyboardEcho ()
  52. SRGP__disableKeyboardEcho ()
  53.       Similar to above: may be called carelessly.
  54.  
  55. **/
  56.  
  57.  
  58. /* FOR LOCATOR ECHO */
  59. static boolean locator_echo_is_active=FALSE;
  60. static RgnHandle savedclip;
  61. static PenState rubberpenstate;
  62. static point echo__locator_rubber_anchor, echo__locator_previous_position;
  63.      /* IN MAC, not SRGP, COORDS */
  64.  
  65. /* FOR KEYBOARD ECHO */
  66. static boolean keyboard_echo_is_active=FALSE;
  67. static int
  68.     /* THE SCREEN LOCATION OF THE ECHO IN THE RAW COORDINATE SYSTEM!
  69.      */
  70.     echo__keyboard_left,   /* X */
  71.     echo__keyboard_origin;  /* Y */
  72.  
  73.  
  74.  
  75. void
  76. SRGP__initEchoModule ()
  77. {
  78.    SRGP__updateKeyboardEchoAttributes ();
  79.  
  80.    /* DEFAULT LOCATOR-ECHO RUBBER ANCHOR (same as keyboard echo). */
  81.    echo__locator_rubber_anchor =
  82.       SRGP_defPoint(echo__keyboard_left, echo__keyboard_origin);
  83.  
  84.    savedclip=NewRgn();
  85.    SetPt (&rubberpenstate.pnSize, 1, 1);
  86.    rubberpenstate.pnMode = patXor;
  87.    memcpy (rubberpenstate.pnPat, black, (size_t)sizeof(Pattern));;
  88. }
  89.  
  90.  
  91.  
  92. static void
  93. ToggleRubberRect (void)
  94. /* DRAWS BETWEEN rubber_anchor AND previous_position */
  95. {
  96.    int tlx, tly, trx, try;
  97.    Rect r;
  98.  
  99.    if (echo__locator_rubber_anchor.x < echo__locator_previous_position.x) {
  100.       tlx = echo__locator_rubber_anchor.x;
  101.       trx = echo__locator_previous_position.x;
  102.    }
  103.    else {
  104.       tlx = echo__locator_previous_position.x;
  105.       trx = echo__locator_rubber_anchor.x;
  106.    }
  107.  
  108.    if (echo__locator_rubber_anchor.y < echo__locator_previous_position.y) {
  109.       tly = echo__locator_rubber_anchor.y;
  110.       try = echo__locator_previous_position.y;
  111.    }
  112.    else {
  113.       tly = echo__locator_previous_position.y;
  114.       try = echo__locator_rubber_anchor.y;
  115.    }
  116.    
  117.    SetRect (&r, tlx, tly, trx, try);
  118.    FrameRect (&r);
  119. }
  120.  
  121.      
  122. static void
  123. ToggleRubberLine (void)
  124. /* DRAWS BETWEEN rubber_anchor AND previous_position */
  125. {
  126.    MoveTo (ExplodePt(echo__locator_previous_position));
  127.    LineTo (ExplodePt(echo__locator_rubber_anchor));
  128. }
  129.  
  130.  
  131. static void
  132. ToggleRubberEcho (void)
  133. {
  134.    PenState savedstate;
  135.    GrafPtr savedgraf;
  136.  
  137.    GetPort (&savedgraf);
  138.    SetPort (srgp__canvasTable[0].drawable.win);
  139.    GetClip (savedclip);
  140.    GetPenState (&savedstate);
  141.  
  142.    SetPenState (&rubberpenstate);
  143.    if (srgp__cur_locator_echo_type == RUBBER_RECT) 
  144.       ToggleRubberRect();
  145.    else
  146.       ToggleRubberLine();
  147.  
  148.    SetPenState (&savedstate);
  149.    SetClip (savedclip);
  150.    SetPort (savedgraf);
  151. }
  152.  
  153.  
  154. void
  155. SRGP__enableLocatorRubberEcho ()
  156. {
  157.    if ( ! locator_echo_is_active)
  158.       if (srgp__cur_mode[LOCATOR] != INACTIVE) 
  159.      if (srgp__cur_locator_echo_type > CURSOR) {
  160.         echo__locator_previous_position =
  161.            SRGP_defPoint 
  162.           (srgp__cur_locator_measure.position.x, 
  163.           SCREENFIXED(srgp__cur_locator_measure.position.y));
  164.         echo__locator_rubber_anchor =
  165.            SRGP_defPoint
  166.           (srgp__cur_locator_echo_anchor.x,
  167.            SCREENFIXED(srgp__cur_locator_echo_anchor.y));
  168.         locator_echo_is_active = TRUE;
  169.         ToggleRubberEcho();
  170.      }
  171. }
  172.  
  173.  
  174. void
  175. SRGP__disableLocatorRubberEcho()
  176. {
  177.    if (locator_echo_is_active) {
  178.       ToggleRubberEcho();
  179.       locator_echo_is_active = FALSE;
  180.    }
  181. }
  182.  
  183.  
  184. void
  185. SRGP__updateLocatorRubberEcho ()
  186. {
  187.    if (locator_echo_is_active) {
  188.       ToggleRubberEcho();
  189.       echo__locator_previous_position =
  190.      SRGP_defPoint (srgp__cur_Xcursor_x, srgp__cur_Xcursor_y);
  191.       ToggleRubberEcho();
  192.    }      
  193. }
  194.    
  195.  
  196.  
  197. void
  198. SRGP__updateLocatorRubberAnchor ()
  199. {
  200.    if (locator_echo_is_active)
  201.       ToggleRubberEcho();
  202.  
  203.    echo__locator_rubber_anchor =
  204.       SRGP_defPoint
  205.      (srgp__cur_locator_echo_anchor.x,
  206.       SCREENFIXED(srgp__cur_locator_echo_anchor.y));
  207.  
  208.    if (locator_echo_is_active)
  209.       ToggleRubberEcho();
  210. }
  211.  
  212.  
  213. void
  214. SRGP__enableLocatorCursorEcho ()
  215. {
  216.    if (srgp__cur_mode[LOCATOR] != INACTIVE) 
  217.       if (srgp__cursorTable[srgp__cur_cursor] == (CursHandle)-1)
  218.          InitCursor();
  219.       else
  220.          SetCursor (*(srgp__cursorTable[srgp__cur_cursor]));
  221. }
  222.  
  223.  
  224. void
  225. SRGP__disableLocatorCursorEcho ()
  226. {
  227.    InitCursor();
  228. }
  229.  
  230.  
  231. void
  232. SRGP__updateLocatorCursorShape ()
  233. {
  234.    SRGP__enableLocatorCursorEcho ();
  235. }
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242. /** KEYBOARD ECHO **/
  243.  
  244. static FontInfo theinfo;
  245. static short overallwidth=0;  /* does not include width of cursor */
  246.  
  247.  
  248. static void
  249. DrawText (void)
  250. {
  251.    CGrafPort saveport;
  252.    CGrafPtr screenport = (CGrafPtr)srgpmac__cwindow;
  253.       
  254.    SetPort (screenport);
  255.    saveport = *screenport;
  256.    
  257.    CtoPstr (srgp__cur_keyboard_measure.buffer);
  258.  
  259.    screenport->fgColor = srgp__cur_keyboard_echo_color;
  260.    TextFont (srgp__fontTable[srgp__cur_keyboard_echo_font].txFont);
  261.    TextSize (srgp__fontTable[srgp__cur_keyboard_echo_font].txSize);
  262.    TextFace (srgp__fontTable[srgp__cur_keyboard_echo_font].txFace);
  263.    PenPat (black);
  264.    TextMode (srcCopy);
  265.    MoveTo (echo__keyboard_left, echo__keyboard_origin);
  266.    DrawString (srgp__cur_keyboard_measure.buffer);
  267.  
  268.    GetFontInfo (&theinfo);
  269.    Move (0, -theinfo.ascent);
  270.    PenSize (5, theinfo.ascent + theinfo.descent);
  271.    Line (0,0);
  272.    
  273.    overallwidth = screenport->pnLoc.h - echo__keyboard_left;
  274.  
  275.    PtoCstr (srgp__cur_keyboard_measure.buffer);
  276.  
  277.    *screenport = saveport;
  278.    
  279.    /* Restore port to what it was before... */
  280.    SetPort (srgp__canvasTable[srgp__curActiveCanvasId].drawable.win);
  281.    
  282. }
  283.  
  284.  
  285. static void
  286. EraseText (void)
  287. {   
  288.    Rect r;
  289.       
  290.    SetPort ((CGrafPtr)srgpmac__cwindow);
  291.    SetRect (&r, echo__keyboard_left, 
  292.            echo__keyboard_origin - theinfo.ascent,
  293.            echo__keyboard_left + overallwidth + 5, 
  294.            echo__keyboard_origin + theinfo.descent);
  295.    EraseRect (&r);
  296.    SetPort (srgp__canvasTable[srgp__curActiveCanvasId].drawable.win);
  297. }
  298.  
  299.  
  300. void
  301. SRGP__enableKeyboardEcho ()
  302. {
  303.    if ( ! keyboard_echo_is_active)
  304.       if (srgp__cur_mode[KEYBOARD] != INACTIVE) 
  305.      if (srgp__cur_keyboard_processing_mode == EDIT) {
  306.         keyboard_echo_is_active = TRUE;
  307.         DrawText();
  308.      }
  309. }
  310.  
  311.  
  312. void
  313. SRGP__disableKeyboardEcho ()
  314. {
  315.    if (keyboard_echo_is_active) {
  316.       EraseText();
  317.       keyboard_echo_is_active = FALSE;
  318.    }
  319. }
  320.  
  321.  
  322. void
  323. SRGP__updateKeyboardEcho ()
  324. {
  325.    if (keyboard_echo_is_active) {
  326.       EraseText();
  327.       DrawText();
  328.    }
  329. }
  330.  
  331.  
  332. void
  333. SRGP__updateKeyboardEchoAttributes ()
  334. {
  335.    if (keyboard_echo_is_active) {
  336.       EraseText();
  337.    }
  338.  
  339.    echo__keyboard_left = srgp__cur_keyboard_echo_origin.x;
  340.    echo__keyboard_origin = SCREENFIXED(srgp__cur_keyboard_echo_origin.y);
  341.  
  342. /*
  343.    XSetForeground (srgpx__display, echo__keyboard_gc, 
  344.            COLORINDEX(srgp__cur_keyboard_echo_color));
  345.    XSetBackground (srgpx__display, echo__keyboard_gc, 
  346.            COLORINDEX(SRGP_WHITE));
  347.    XSetFont (srgpx__display, echo__keyboard_gc, 
  348.          (echo__keyboard_font =
  349.             srgp__fontTable[srgp__cur_keyboard_echo_font])->fid);
  350. */
  351.  
  352.    if (keyboard_echo_is_active) {
  353.       DrawText();
  354.    }
  355. }
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.